<?php
    @header('Content-type:text/html;charset=utf-8');
    // 全栈开发工程师

    @include_once('conn.php');
    @include_once('noparams.php');
    

    // 接收参数
    $user = $_POST["user"];
    $phone = $_POST["phone"];
    $pass = $_POST["pass"];
    $email = $_POST["email"];

    if(!($user&&$phone&&$pass&&$email)){
        NoParamsErr();
    }

    $sql = "insert into users (user,pass,phone,email) values ('$user','$pass','$phone','$email') ";

    $result = mysqli_query($conn,$sql);

    if(!$result){
        $obj = array();
        $obj['status'] = false;
        $obj['detail'] = "Sql语句有问题";
        $obj['sql'] = $sql;
        exit(json_encode($obj));
    }

    // mysqli_affected_rows($conn)  传入mysql 链接对象 $conn 返回受影响的行数 
    // row > 0  新增成功
    // row  == -1 新增失败 sql 语句有问题
    $rows = mysqli_affected_rows($conn);
    $obj = array();
    $obj['status'] = true;
    $obj['detail'] = "注册成功";

    echo json_encode($obj);

?>